package com.example.administrator.familfinalcialmanagement.util.dialog;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.databinding.DialogPayBinding;
import com.example.administrator.familfinalcialmanagement.util.ToastUtil;
import com.example.administrator.familfinalcialmanagement.util.listener.OnGRClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by SensYang on 2019/04/02 0:55
 * 1 微信、2支付宝 3 现金 4 信用卡 5 储蓄卡
 */

public class PayDialog extends BaseDialog implements View.OnClickListener {

    Context context;
    DialogPayBinding binding;
    String select = "";
    OnGRClickListener listener;
    List<TextView> list = new ArrayList<>();

    public void setOnGRClickListener(OnGRClickListener listener) {
        this.listener = listener;
    }

    public PayDialog(Context context) {
        super(context);
        this.context = context;
        binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_pay, null, false);
        binding.setDialog(this);
        setContentView(binding.getRoot());
        initView();
    }

    private void initView() {
        list.add(binding.tvModuleWeixin);
        list.add(binding.tvModuleZhifubao);
        list.add(binding.tvModuleXianjin);
        list.add(binding.tvModuleChuxuka);
        list.add(binding.tvModuleXinyongka);

        binding.tvModuleWeixin.setOnClickListener(this);
        binding.tvModuleZhifubao.setOnClickListener(this);
        binding.tvModuleXianjin.setOnClickListener(this);
        binding.tvModuleChuxuka.setOnClickListener(this);
        binding.tvModuleXinyongka.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvModuleWeixin:
                select = "微信钱包";
                setOtherTextColor(binding.tvModuleWeixin);
                break;
            case R.id.tvModuleZhifubao:
                select = "支付宝";
                setOtherTextColor(binding.tvModuleZhifubao);
                break;
            case R.id.tvModuleXianjin:
                select = "现金";
                setOtherTextColor(binding.tvModuleXianjin);
                break;
            case R.id.tvModuleChuxuka:
                select = "储蓄卡";
                setOtherTextColor(binding.tvModuleChuxuka);
                break;
            case R.id.tvModuleXinyongka:
                select = "信用卡";
                setOtherTextColor(binding.tvModuleXinyongka);
                break;
            default:
        }
    }

    public void setOtherTextColor(TextView text) {
        for (TextView tv : list) {
            tv.setTextColor(context.getResources().getColor(R.color.tv_1));
        }
        text.setTextColor(context.getResources().getColor(R.color.A1E0F2));
    }

    public void noPoint(View view) {
        if (listener != null) {
            listener.setOnCloseClick();
        }
        dismiss();
    }

    public void okPoint(View view) {
        if ("0".equals(select)) {
            ToastUtil.showToast("请选择消费归属");
            return;
        }

        if (listener != null) {
            listener.setOnConfirmClick(select);
        }
        dismiss();
    }
}